#include "line.h"
#include <QLineF>
#include <QPainter>
#include <QPen>

Line::Line(qreal x1, qreal y1, qreal x2, qreal y2):QGraphicsLineItem(x1,y1,x2,y2){
    m_start = new QPointF(x1,y1);
    m_end = new QPointF(x2,y2);

}

void
Line::setStart(qreal nx1, qreal ny1){
    setLine(nx1,ny1,m_end->x(),m_end->y());
    m_start->setX(nx1);
    m_start->setY(ny1);
}

void
Line::setEnd(qreal nx2,qreal ny2){
     setLine(m_start->x(),m_start->y(),nx2,ny2);
     m_end->setX(nx2);
     m_end->setY(ny2);
}

void
Line::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    if(isSelected()){
        QPen pen;
        pen.setColor(Qt::red);
        pen.setWidth(3);
        painter->setPen(pen);
        painter->drawLine(*m_start,*m_end);
    } else {
        QGraphicsLineItem::paint(painter,option,widget);
    }
}
